package com.shuiyun.controller;

import com.shuiyun.entity.Goods;
import com.shuiyun.service.GoodsService;
import com.shuiyun.utils.DataGridResult;
import com.shuiyun.utils.Query;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Controller
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @RequestMapping("goods/list")
    @ResponseBody
    public DataGridResult goList(@RequestParam Map<String, Object> map){

        return goodsService.findAllGoods(new Query(map));
    }

    @RequestMapping("goods/info/{goodsId}")
    @ResponseBody
    public Goods goodsInfo(@PathVariable Integer goodsId){

        return goodsService.findGoodsById(goodsId);
    }

    @RequestMapping("goods/update")
    @ResponseBody
    public int updateGoods(@RequestBody Goods goods){

        return goodsService.updateGoods(goods);
    }

    @RequestMapping("/goods/del")
    @ResponseBody
    public int deleteGoods(@RequestBody Integer[] ids){

        return goodsService.deleteGoods(ids);
    }

    @RequestMapping("/goods/add")
    @ResponseBody
    public int addGoods(@RequestBody Goods goods){
        return goodsService.addGoods(goods);
    }
}
